/*******************************************************************************
 * Copyright (c) 2014 Francesco Gabbrielli
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Francesco Gabbrielli - initial API and implementation
 ******************************************************************************/
package it.francescogabbrielli.android.solidalapp.home;

import it.francescogabbrielli.android.solidalapp.BaseFragment;
import it.francescogabbrielli.android.solidalapp.DataEvent;
import it.francescogabbrielli.android.solidalapp.R;
import it.francescogabbrielli.android.solidalapp.StatusEvent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * 
 */
public class RequestFragment extends BaseFragment<HomeFragmentListener> {

	private RequestDataFragment dataFragment;
	private RequestMapFragment mapFragment;
	
	public RequestFragment() {
		
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_request, container, false);
	}
	
	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		
		final FragmentManager manager = getChildFragmentManager();
		
		dataFragment = (RequestDataFragment) getChildFragmentManager().findFragmentByTag("request_data");
		mapFragment = (RequestMapFragment) getChildFragmentManager().findFragmentByTag("request_map");
		if(dataFragment==null && getResources().getBoolean(R.bool.notabs)) {
			dataFragment = new RequestDataFragment();
			mapFragment = new RequestMapFragment();
			FragmentTransaction ft = manager.beginTransaction();
			ft.replace(R.id.request_data_container, dataFragment, "request_data");
			ft.replace(R.id.request_map_container, mapFragment, "request_map");
			ft.commit();
		}

		super.onViewCreated(view, savedInstanceState);
		
	}
	
	@Override
	public void onDestroy() {
		super.onDestroy();
	}
	
	@Override
	public void onStatusUpdate(StatusEvent event) {
		
	}
	
	@Override
	public void onDataChanged(DataEvent event) {
		
	}
	
}
